//
//  HNSH_OrderListCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/1.
//

#import "HNSH_OrderListCell.h"

@interface HNSH_OrderListCell ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;

/* goodsimgV */
@property (nonatomic, strong) UIImageView *goodsimgV;
/* goodsNameLabel */
@property (nonatomic, strong) UILabel *goodsNameLabel;
/* goodsSpecLabel */
@property (nonatomic, strong) UILabel *goodsSpecLabel;
/* goodsPriceLabel */
@property (nonatomic, strong) UILabel *goodsPriceLabel;
/* goodsCountLabel */
@property (nonatomic, strong) UILabel *goodsCountLabel;

@end

@implementation HNSH_OrderListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor appBGColor];
        [self configView];
    }
    return self;
}

//MARK: Setter Methods
- (void)setModel:(HNSH_ConfirmOrderGoodsModel *)model{
    _model = model;
    
    [self.goodsimgV sd_setImageWithURL:[NSURL URLWithString:model.left_icon] placeholderImage:[UIImage imageNamed:@"icon_place_zfx"]];
    self.goodsNameLabel.text = model.title;
    self.goodsSpecLabel.text = model.sku_text;
    self.goodsPriceLabel.attributedText = [NSString transAttWithSting:model.price_text];
    self.goodsCountLabel.text = model.quantity_text;
}

- (void)configView {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.goodsimgV];
    [self.bgView addSubview:self.goodsNameLabel];
    [self.bgView addSubview:self.goodsSpecLabel];
    [self.bgView addSubview:self.goodsPriceLabel];
    [self.bgView addSubview:self.goodsCountLabel];
    
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(20, 0, kScreenWidth-40, 106)];
        _bgView.backgroundColor = [UIColor appWhiteLabelColor];
    }
    return _bgView;
}

- (UIImageView *)goodsimgV {
    if (!_goodsimgV) {
        _goodsimgV = [[UIImageView alloc]initWithFrame:CGRectMake(8, 8, 90, 90)];
        _goodsimgV.layer.cornerRadius = 8.0f;
        _goodsimgV.layer.masksToBounds = YES;
    }
    return _goodsimgV;
}

- (UILabel *)goodsNameLabel {
    if (!_goodsNameLabel) {
        _goodsNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(113, 8, kScreenWidth-160, 22)];
        _goodsNameLabel.text = @"";
        _goodsNameLabel.textColor = [UIColor appBlackLabelColor];
        _goodsNameLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _goodsNameLabel;
}

- (UILabel *)goodsSpecLabel {
    if (!_goodsSpecLabel) {
        _goodsSpecLabel = [[UILabel alloc]initWithFrame:CGRectMake(113, 35, kScreenWidth-160, 16)];
        _goodsSpecLabel.text = @"";
        _goodsSpecLabel.textColor = [UIColor appGrayLabelColor];
        _goodsSpecLabel.font = [UIFont systemFontOfSize:12];
    }
    return _goodsSpecLabel;
}

- (UILabel *)goodsPriceLabel {
    if (!_goodsPriceLabel) {
        _goodsPriceLabel = [[UILabel alloc]initWithFrame:CGRectMake(113, 76, 160, 22)];
        _goodsPriceLabel.text = @"";
        _goodsPriceLabel.textColor = [UIColor appGreenColor];
        _goodsPriceLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _goodsPriceLabel;
}

- (UILabel *)goodsCountLabel {
    if (!_goodsCountLabel) {
        _goodsCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth-48-100, 76, 100, 17)];
        _goodsCountLabel.text = @"";
        _goodsCountLabel.textColor = [UIColor appGrayLabelColor];
        _goodsCountLabel.font = [UIFont systemFontOfSize:13];
        _goodsCountLabel.textAlignment = NSTextAlignmentRight;
    }
    return _goodsCountLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
